package com.augurit.common.tag.link;

import java.io.Writer;

import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.apache.struts2.components.Component;

import sun.reflect.generics.tree.Tree;

import com.opensymphony.xwork2.util.ValueStack;

/**
 * Buttons的业务逻辑Bean
 * 
 * @author Administrator
 * 
 */
public class Links extends Component {

	private String href;
	private String id;
	private String debug;
	private String content;
	private String title;
	private String onfocus;
	private String onblur;
	private String onclick;
	private String onkeydown;
	private String onkeypress;
	private String onkeyup;
	private String sessionPrivilege;
	// 属性get和set方法
	
	
	public String getSessionPrivilege() {
		return sessionPrivilege;
	}

	public void setSessionPrivilege(String sessionPrivilege) {
		this.sessionPrivilege = sessionPrivilege;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getHref() {
		return href;
	}

	public void setHref(String href) {
		this.href = href;
	}

	public Links(ValueStack arg0) {
		super(arg0);
	}

	@Override
	public boolean start(Writer arg0) {
		boolean result = super.start(arg0);
		try {
			StringBuilder str = new StringBuilder();
			// 判断是否在权限内
			if (sessionPrivilege!=null && sessionPrivilege.indexOf("," + id + ",") >= 0) {
				str.append("<a ");
				if (href != null) {
					str.append("href=\"" + href + "\"");
				}
				if (id != null) {
					str.append("id=\"" + id + "\"");
				}
				
				if (title != null) {
					str.append("title=\"" + title + "\"");
				}
				if (onfocus != null) {
					str.append("onfocus=\"" + onfocus + "\"");
				}
				if (onblur != null) {
					str.append("onblur=\"" + onblur + "\"");
				}
				if (onclick != null) {
					str.append("onclick=\"" + onclick + "\"");
				}
				if (onkeydown != null) {
					str.append("onkeydown=\"" + onkeydown + "\"");
				}
				if (onkeypress != null) {
					str.append("onkeypress=\"" + onkeypress + "\"");
				}
				if (onkeyup != null) {
					str.append("onkeyup=\"" + onkeyup + "\"");
				}				
					str.append("\">"+content+"</a>");
				
			} else {
				str.append("");
			}
			if( debug !=null && debug.equals("true")){
				String string = str.toString();
				str.append("</br>"+"<label>"+"该连接的id是："+id+"；session所包含的权限为"+sessionPrivilege
						+"</label>"+"</br>");					
			}
			arg0.write(str.toString());
		} catch (Exception e) {
			Logger.getLogger(Tree.class.getName()).log(Level.WARN, null, e);
		}
		return result;

	}

	public String getDebug() {
		return debug;
	}

	public void setDebug(String debug) {
		this.debug = debug;
	}

	public String getTitle() {
		return title;
	}

	public String getOnfocus() {
		return onfocus;
	}

	public String getOnblur() {
		return onblur;
	}

	public String getOnclick() {
		return onclick;
	}

	public String getOnkeydown() {
		return onkeydown;
	}

	public String getOnkeypress() {
		return onkeypress;
	}

	public String getOnkeyup() {
		return onkeyup;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public void setOnfocus(String onfocus) {
		this.onfocus = onfocus;
	}

	public void setOnblur(String onblur) {
		this.onblur = onblur;
	}

	public void setOnclick(String onclick) {
		this.onclick = onclick;
	}

	public void setOnkeydown(String onkeydown) {
		this.onkeydown = onkeydown;
	}

	public void setOnkeypress(String onkeypress) {
		this.onkeypress = onkeypress;
	}

	public void setOnkeyup(String onkeyup) {
		this.onkeyup = onkeyup;
	}

	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}

	

}
